package com.hrg.rds.biz.waybill.domain.instance;

import cn.hutool.core.collection.CollUtil;
import com.hrg.rds.biz.waybill.domain.template.cmd.Cmd;
import com.hrg.rds.biz.waybill.domain.template.cmd.CmdParam;
import com.hrg.rds.biz.waybill.domain.template.cmd.CmdType;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class CmdInstanceVo {
    private String id;
    private String parentId;
    private Cmd cmd;
    private List<CmdInstanceVo> children;
    //运单实例
    private String waybillInstanceId;
    private CmdType cmdType;
    private int order;
    //输入参数
    private List<CmdParam> inputParams;
    //输出参数
    private List<CmdParam> outputParams;

    //执行开始时间
    private Date startTime;
    //执行结束时间
    private Date endTime;

    //码
    private CmdInstanceCode code;
    //信息
    private String msg;

    private List<AgvMsg> agvMsgs;

    public AgvMsg findChildAgvMsg(String id) {
        if (this.id.equals(id)) {
            if (CollUtil.isNotEmpty(agvMsgs)) {
                return agvMsgs.getFirst();
            }
        }
        if (CollUtil.isNotEmpty(children)) {
	        for (CmdInstanceVo child : children) {
		        return child.findChildAgvMsg(id);
	        }
        }
        return null;
    }
}
